#include<iostream>
#include<memory>
#include<unistd.h>
#include"Socket.hpp"

using namespace SocketModule;

class SelectServer
{
public:
	SelectServer(int port)
	:_listensock(std::make_unique<TcpSocket>())
	,_isrunning(false)
	{
		_listensock->BuildTcpSocketMethod(port);
	} 
	void Start()
	{
		//通过 _isrunning 标志控制循环的启停
		_isrunning = true;
		while(_isrunning)//事件监听逻辑
		{
			fd_set rfds;// 定义fds集合
			FD_ZERO(&rfds);// 清空fds
			FD_SET(_listensock->Fd(), &rfds);

			int n = select(_listensock->Fd()+1, &rfds, nullptr, nullptr, nullptr);
		}
		_isrunning = false;
	}

	void Stop()
    {
        _isrunning = false;
    }

    ~SelectServer()
    {}
	
private:
	std::unique_ptr<Socket> _listensock;
	bool _isrunning;
};